package com.easybuy.entity;
/**
 * EasybuyUser 实体类
 * 对应数据库表 easybuy.easybuy_user
 */
public class EasybuyUser {
    // 主键
    private Integer id;

    // 登录名
    private String loginName;

    // 用户名
    private String userName;

    // 密码
    private String password;

    // 性别(1:男 0：女)
    private Integer sex;

    // 身份证号
    private String identityCode;

    // 邮箱
    private String email;

    // 手机
    private String mobile;

    // 类型（1：后台 0:前台）
    private Integer type;

    // 无参构造函数
    public EasybuyUser() {
    }

    // 带参构造函数
    public EasybuyUser(Integer id, String loginName, String userName, String password,
                      Integer sex, String identityCode, String email, String mobile, Integer type) {
        this.id = id;
        this.loginName = loginName;
        this.userName = userName;
        this.password = password;
        this.sex = sex;
        this.identityCode = identityCode;
        this.email = email;
        this.mobile = mobile;
        this.type = type;
    }

    // Getter 和 Setter 方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getIdentityCode() {
        return identityCode;
    }

    public void setIdentityCode(String identityCode) {
        this.identityCode = identityCode;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    // 便捷方法：判断性别是否为男性
    public boolean isMale() {
        return sex != null && sex == 1;
    }

    // 便捷方法：判断性别是否为女性
    public boolean isFemale() {
        return sex != null && sex == 0;
    }

    // 便捷方法：设置性别为男性
    public void setMale() {
        this.sex = 1;
    }

    // 便捷方法：设置性别为女性
    public void setFemale() {
        this.sex = 0;
    }

    // 便捷方法：获取性别描述
    public String getSexDescription() {
        if (sex == null) return "未知";
        return sex == 1 ? "男" : "女";
    }

    // 便捷方法：判断是否为后台用户
    public boolean isAdmin() {
        return type != null && type == 1;
    }

    // 便捷方法：判断是否为前台用户
    public boolean isFrontendUser() {
        return type == null || type == 0;
    }

    // 便捷方法：设置用户类型为后台用户
    public void setAdmin() {
        this.type = 1;
    }

    // 便捷方法：设置用户类型为前台用户
    public void setFrontendUser() {
        this.type = 0;
    }

    // 便捷方法：获取用户类型描述
    public String getTypeDescription() {
        if (type == null) return "前台用户";
        return type == 1 ? "后台用户" : "前台用户";
    }

    // 便捷方法：验证手机号格式（简单验证）
    public boolean isMobileValid() {
        if (mobile == null || mobile.trim().isEmpty()) {
            return false;
        }
        // 简单的手机号格式验证：11位数字
        return mobile.matches("^1[3-9]\\d{9}$");
    }

    // 便捷方法：验证邮箱格式（简单验证）
    public boolean isEmailValid() {
        if (email == null || email.trim().isEmpty()) {
            return false;
        }
        // 简单的邮箱格式验证
        return email.matches("^[A-Za-z0-9+_.-]+@(.+)$");
    }

    @Override
    public String toString() {
        return "EasybuyUser{" +
                "id=" + id +
                ", loginName='" + loginName + '\'' +
                ", userName='" + userName + '\'' +
                ", password='[PROTECTED]'" +
                ", sex=" + sex +
                ", identityCode='" + identityCode + '\'' +
                ", email='" + email + '\'' +
                ", mobile='" + mobile + '\'' +
                ", type=" + type +
                '}';
    }
}